<template>
  <div class="wrapper">
    <!-- <Anchor :labelList="labels" activeId="row-01" labelWidth="100"> -->
      <div class="line" id="row-01">
        <BreakSpace label="基本信息" :containerStyle="{ marginBottom: '10px' }" />
        <InfoBase ref="InfoBaseRef" v-model="value"/>
      </div>
      <div class="line" id="row-02">
        <BreakSpace label="项目列表" :containerStyle="{ marginBottom: '10px' }" />
        <infoActivity ref="InfoActivityRef" v-model="value" :flag="push" />
      </div>
      <div class="line" id="row-03">
        <BreakSpace label="营销素材列表" :containerStyle="{ marginBottom: '10px' }" />
        <infoGoods ref="InfoGoodsRef" v-model="value" :flag="push" />
      </div>
      <div class="line" id="row-04">
        <BreakSpace label="经销商列表" :containerStyle="{ marginBottom: '10px' }" />
        <infoDealer ref="InfoDealerRef" v-model="value" />
      </div>
    <!-- </Anchor> -->
    <div class="dialogBottmView">
      <el-button
        @click="feiChuFaDialog"
        v-if="this.btnFeiChuStatus == true"
        type="primary"
      >废 除</el-button>
      <el-button @click="closeDialog">关 闭</el-button>
    </div>
  </div>
</template>

<script>
import { authority } from '@/utils/authMixin';
import { dictionary } from '@/utils/dictMixin';
import InfoBase from '@/pages/cms-pages/projectOperating/program/departmentInquire/detail-base.vue'; //基本信息
import infoActivity from '../commonForm/detail-infoActivity'; //活动列表
import infoGoods from '../commonForm/detail-infoGoods'; //物料列表
import infoDealer from '../commonForm/detail-dealer'; //经销商列表
import { getLoginUser } from '@/api/cms-api/projectOperating/program/departmentInquire';//获取登录信息
import { updateExcercise } from '@/api/cms-api/projectOperating/program/push';//api 项目方案-废除
export default {
  mixins: [authority, dictionary],
  components: {
    InfoBase,
    infoActivity,
    infoGoods,
    infoDealer
  },
  props: {
    //方案信息，格式： { type: type,  //页面类型
    //                  rowData: row }  //查询列表中对应方案数据
    //                                    （注：需要包含projectProgramId：方案ID和projectProgramOrgId：营销方案事业部ID和orgStatus：事业部下发状态）
    value: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      inClick: 0, //点击按钮的入口 0:保存,1:下发,2:废除
      loginUser: null, //登录用户信息
      btnFeiChuStatus: false, //废除按钮是否显示状态，true显示
      caseUrlList: [],
      typeZ: '',
      push: 'push',
      result: {},
      infoBaseValue: {},
      infoGoodsRefValue: {},
      infoActivityRefValue: {},
      infoDealerRefValue: {},
      labels: [{ title: '基本信息', id: 'row-01' }, { title: '项目列表', id: 'row-02' }, { title: '营销素材列表', id: 'row-03' }, { title: '经销商列表', id: 'row-04' }]
    };
  },
  mounted() {
    //根据登录人来判断是否显示废除按钮
    this.loadUserInfo();
  },
  computed: {
  },
  methods: {
    //根据登录人来判断是否显示废除按钮
    async loadUserInfo() {
      let isShowFeiChuBtn = true;
      //如果没有传参数（isShowFeiChuBtn）或isShowFeiChuBtn=true显示废除按钮
      if(this.value.rowData
         && this.value.rowData.isShowFeiChuBtn!=null
        && typeof(this.value.rowData.isShowFeiChuBtn)!='undefined'
        && this.value.rowData.isShowFeiChuBtn==false){
        isShowFeiChuBtn = false;
      }
      if(isShowFeiChuBtn){
        this.loginUser = await getLoginUser({});
        //已分配的方案只有自己方案分配人的方案可以废除，同时已经废除不需要再废除（事业部分配状态和事业部分配人）
        if (this.loginUser.data.userId == this.value.rowData.distributionPerson //登录人同下发人为同一人
            && this.value.rowData.orgStatus == 25281002 //事业部下发状态为已下发
            && this.value.rowData.programIssuedChannel==25301002) {//事业部下发
          this.btnFeiChuStatus = true;
        }
      }
    },
    //废除方案
    async feiChuFaDialog() {
      this.inClick = 2;
      this.infoBaseValue = this.$refs.InfoBaseRef.value.rowData;
      this.infoBaseValue.programStatus = 25281003;
      var arr = {};
      arr.programStatus = 25281003; //已作废
      arr.projectProgramId = this.value.rowData.projectProgramId;
      const res = await updateExcercise(this.value.rowData.projectProgramId, arr);

      if (res.resultCode === 200) {
        this.$notify.success({ title: '提示信息', message: '废除成功!' });
        // 重新加载
        this.closeDialog(true);
      } else {
        this.$notify.error({ title: '提示信息', message: res.errMsg || '废除失败!' });
        this.closeDialog();
      }
    },
    //关闭
    closeDialog(isRefresh) {
      this.value.type = '';
      this.$emit('close', { visible: false ,refresh:isRefresh});
    }
  }
};
</script>
<style scoped>
.wrapper {
  height: calc(100vh - 110px);
}
</style>
